/**
 * 给定数组A，求 SIGMA{SIGMA{(Ai - Aj) ^ 2}}
 * 推一个公式很容易得到。
 */
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long llt;

int getInt(){
	int sgn = 1;
	char ch = getchar();
	while( ch != '-' && ( ch < '0' || ch > '9' ) ) ch = getchar();
	if ( '-' == ch ) {sgn = 0;ch=getchar();}

	int ret = (int)(ch-'0');
	while( '0' <= (ch=getchar()) && ch <= '9' ) ret = ret * 10 + (int)(ch-'0');
	return sgn ? ret : -ret;
}

llt const MOD = 1000000007LL;
inline llt add(llt a,llt b){
    return (a+b)%MOD;
}
inline llt add(llt a,llt b,llt c){
    return (add(a,b)+c)%MOD;
}
inline llt mul(llt a,llt b){
    return a*b%MOD;
}
inline llt mul(llt a,llt b,llt c){
    return mul(a,b)*c%MOD;
}
llt A[500010];
llt B[500010];
llt Fang[500010], JI[500010];
llt idi[500010];
llt He[500010];
int main(){
    //freopen("H:\\CppProject\\acmt2\\1.txt","r",stdin);
    int n;
    while(EOF!=scanf("%d",&n)){
    for(int i=0;i<n;++i)scanf("%d",A+i);
    sort(A,A+n);
    B[0] = 0LL;
    for(int i=1;i<n;++i)B[i]=A[i]-A[i-1];
    llt ans = 0LL;
    fill(Fang,Fang+n+1,0LL);
    fill(JI,JI+n+1,0LL);
    fill(idi,idi+n+1,0LL);
    fill(He,He+n+1,0LL);
    for(int i=1;i<n;++i){
        idi[i] = add(mul(i, B[i]) , idi[i-1]);
        Fang[i] = add(mul(i,B[i],B[i]) , Fang[i-1]);
        JI[i] = mul(2,B[i],idi[i-1]);
        He[i] = add(JI[i] , He[i-1]);
        ans = add(ans, Fang[i], He[i]);
    }
    printf("%lld\n",ans);
    }
    return 0;
}
